// 引入Ajax axios库
import axios from "axios";
// 创建axios并封装api请求
import { loading } from "element-ui";
const requests = axios.create({
  baseURL: "http://124.223.70.80:8011",
  timeout: 10000,
});
let loadingInstance;

// 请求拦截
requests.interceptors.request.use(
  (config) => {
    loadingInstance = loading.service({
      //加载loading
      fullscreen: true,
      text: "拼命加载中",
      spinner: "el-icon-loading",
      background: "rgba(0, 0, 0, 0.7)",
    });
    return config;
  },
  (err) => {
    return Promise.reject(err);
  }
);
// 响应拦截
requests.interceptors.response.use(
  (res) => {
    loadingInstance.close();
    return res;
  },
  (err) => {
    return Promise.reject(err);
  }
);
//暴露requests
export default requests;
